/**
 * 日历工具类
 */
export const dayArr = ['日', '一', '二', '三', '四', '五', '六'];

export class DateUtil {

  /**
   * 小于10数字前缀补0
   */
  static dateFormat = (time: number) => {
    return `${time >= 10 ? time : '0' + time}`;
  }

  /**
   * 获取当前日期
   */
  static getCurrent = () => {
    const date = new Date();
    const year = date.getFullYear();
    const month = date.getMonth() + 1;
    const day = date.getDate();
    return year + DateUtil.dateFormat(month) + DateUtil.dateFormat(day);
  }

  static changeTimeStr = (time: string) => {
    return time.split('-').map((el) => Number(el));
  }

  static getCurrentStr = (isZero: boolean = false) => {
    const date = new Date();
    return isZero ? date.getFullYear() + '-' + DateUtil.dateFormat(date.getMonth() + 1)
           + DateUtil.dateFormat(date.getDate()) : date.getFullYear()
           + '-' + (date.getMonth() + 1) + '-' + date.getDate();
  }
  /**
   * 获取公历某一天是星期几
   * @param {number} y 年
   * @param {number} m 月
   * @param {number} d 天
   * @returns {number} 返回星期数字[0-6]
   */
  static solarWeek = (y: number, m: number, d: number) => {
    const date = new Date(y, m - 1, d);
    const week = date.getDay();
    return week;
  }


}